/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

// snddma_null.c
// all other sound mixing is portable

#ifdef GCCBROKENRELATIVEPATHS
#include "../../client/client.h"
#include "../../client/snd_loc.h"
#else
#include "../client/client.h"
#include "../client/snd_loc.h"
#endif

#include "kernel.h"
#include "DRender.h"

static void * buffer;
qboolean SNDDMA_Init(void)
{
//    dma.samplebits       = 16;
//    dma.speed            = 22050;
//    dma.channels         = 2;
//    dma.samples          = 1024 * 16;
//    dma.submission_chunk = 2048;
//    dma.buffer           = NULL;
//    buffer = malloc(dma.samples * (dma.samplebits / 8));
//
//    if (buffer)
//    {
//        DigitalRenderer_StreamFlags(1 | 5, 0);
//        DigitalRenderer_NumBuffers(16);
//        DigitalRenderer_ActivateAuto(2, 1024 / dma.channels, dma.speed * 1024);
//    }
//
//    return buffer ? true : false;
    return false;
}

int done = 0;

int SNDDMA_GetDMAPos(void)
{
    return done;// & (dma.samples - 1);
}

void SNDDMA_Shutdown(void)
{
    if (buffer != NULL) free(buffer);

    DigitalRenderer_Deactivate();
}

void SNDDMA_BeginPainting (void)
{
    dma.buffer = buffer;
}

void SNDDMA_Submit(void)
{
    int amount = (16 - DigitalRenderer_StreamStatistics()) * 1024;

    // Play data in dma.buffer
    DigitalRenderer_Stream16BitSamples((unsigned short*)dma.buffer, amount + 1024);

    done += amount;

    dma.buffer = NULL;
}
